added amb1119 - sm_revote command
--HG-- extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%402151
This commit is contained in:
parent
0fac3fd74e
commit
b2fbd9691d
@ -790,3 +790,13 @@ unsigned int MenuManager::GetRemainingVoteDelay()
|
|||||||
{
|
{
|
||||||
return s_VoteHandler.GetRemainingVoteDelay();
|
return s_VoteHandler.GetRemainingVoteDelay();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool MenuManager::IsClientInVotePool(int client)
|
||||||
|
{
|
||||||
|
return s_VoteHandler.IsClientInVotePool(client);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool MenuManager::RedrawClientVoteMenu(int client)
|
||||||
|
{
|
||||||
|
return s_VoteHandler.RedrawToClient(client);
|
||||||
|
}
|
||||||
|
@ -89,6 +89,8 @@ public:
|
|||||||
bool IsVoteInProgress();
|
bool IsVoteInProgress();
|
||||||
void CancelVoting();
|
void CancelVoting();
|
||||||
unsigned int GetRemainingVoteDelay();
|
unsigned int GetRemainingVoteDelay();
|
||||||
|
bool IsClientInVotePool(int client);
|
||||||
|
bool RedrawClientVoteMenu(int client);
|
||||||
public: //IHandleTypeDispatch
|
public: //IHandleTypeDispatch
|
||||||
void OnHandleDestroy(HandleType_t type, void *object);
|
void OnHandleDestroy(HandleType_t type, void *object);
|
||||||
bool GetHandleApproxSize(HandleType_t type, void *object, unsigned int *pSize);
|
bool GetHandleApproxSize(HandleType_t type, void *object, unsigned int *pSize);
|
||||||
|
@ -113,14 +113,19 @@ void VoteMenuHandler::OnClientDisconnected(int client)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Wipe out their vote if they had one */
|
/* Wipe out their vote if they had one. We have to make sure the the the
|
||||||
|
* newly connected client is not allowed to vote.
|
||||||
|
*/
|
||||||
int item;
|
int item;
|
||||||
if ((item = m_ClientVotes[client]) >= 0)
|
if ((item = m_ClientVotes[client]) >= -1)
|
||||||
{
|
{
|
||||||
assert((unsigned)item < m_Items);
|
if (item >= 0)
|
||||||
assert(m_Votes[item] > 0);
|
{
|
||||||
m_Votes[item]--;
|
assert((unsigned)item < m_Items);
|
||||||
m_ClientVotes[client] = -1;
|
assert(m_Votes[item] > 0);
|
||||||
|
m_Votes[item]--;
|
||||||
|
}
|
||||||
|
m_ClientVotes[client] = -2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -129,18 +134,28 @@ bool VoteMenuHandler::IsVoteInProgress()
|
|||||||
return (m_pCurMenu != NULL);
|
return (m_pCurMenu != NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool VoteMenuHandler::StartVote(IBaseMenu *menu, unsigned int num_clients, int clients[], unsigned int max_time, unsigned int flags/* =0 */)
|
bool VoteMenuHandler::StartVote(IBaseMenu *menu,
|
||||||
|
unsigned int num_clients,
|
||||||
|
int clients[],
|
||||||
|
unsigned int max_time,
|
||||||
|
unsigned int flags/* =0 */)
|
||||||
{
|
{
|
||||||
if (!InitializeVoting(menu, menu->GetHandler(), max_time, flags))
|
if (!InitializeVoting(menu, menu->GetHandler(), max_time, flags))
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Note: we can use game time and not universal time because
|
||||||
|
* if we're voting then players are in-game.
|
||||||
|
*/
|
||||||
|
|
||||||
float fVoteDelay = sm_vote_delay.GetFloat();
|
float fVoteDelay = sm_vote_delay.GetFloat();
|
||||||
if (fVoteDelay < 1.0)
|
if (fVoteDelay < 1.0)
|
||||||
{
|
{
|
||||||
g_next_vote = 0.0;
|
g_next_vote = 0.0;
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
/* This little trick breaks for infinite votes!
|
/* This little trick breaks for infinite votes!
|
||||||
* However, we just ignore that since those 1) shouldn't exist and
|
* However, we just ignore that since those 1) shouldn't exist and
|
||||||
* 2) people must be checking IsVoteInProgress() beforehand anyway.
|
* 2) people must be checking IsVoteInProgress() beforehand anyway.
|
||||||
@ -148,8 +163,15 @@ bool VoteMenuHandler::StartVote(IBaseMenu *menu, unsigned int num_clients, int c
|
|||||||
g_next_vote = gpGlobals->curtime + fVoteDelay + (float)max_time;
|
g_next_vote = gpGlobals->curtime + fVoteDelay + (float)max_time;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m_fStartTime = gpGlobals->curtime;
|
||||||
|
m_nMenuTime = max_time;
|
||||||
|
|
||||||
for (unsigned int i=0; i<num_clients; i++)
|
for (unsigned int i=0; i<num_clients; i++)
|
||||||
{
|
{
|
||||||
|
if (clients[i] < 1 || clients[i] > 256)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
menu->Display(clients[i], max_time, this);
|
menu->Display(clients[i], max_time, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -158,6 +180,58 @@ bool VoteMenuHandler::StartVote(IBaseMenu *menu, unsigned int num_clients, int c
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool VoteMenuHandler::IsClientInVotePool(int client)
|
||||||
|
{
|
||||||
|
if (client < 1
|
||||||
|
|| client > g_Players.MaxClients()
|
||||||
|
|| m_pCurMenu == NULL)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (m_ClientVotes[client] > -2);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool VoteMenuHandler::GetClientVoteChoice(int client, unsigned int *pItem)
|
||||||
|
{
|
||||||
|
if (!IsClientInVotePool(client)
|
||||||
|
|| m_ClientVotes[client] == -1)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
*pItem = m_ClientVotes[client];
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool VoteMenuHandler::RedrawToClient(int client)
|
||||||
|
{
|
||||||
|
unsigned int time_limit;
|
||||||
|
|
||||||
|
if (!IsClientInVotePool(client))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (m_nMenuTime == MENU_TIME_FOREVER)
|
||||||
|
{
|
||||||
|
time_limit = m_nMenuTime;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
time_limit = (int)((float)m_nMenuTime - (gpGlobals->curtime - m_fStartTime));
|
||||||
|
|
||||||
|
/* Make sure this doesn't round to zero */
|
||||||
|
if (time_limit == MENU_TIME_FOREVER)
|
||||||
|
{
|
||||||
|
time_limit = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return m_pCurMenu->Display(client, time_limit, this);
|
||||||
|
}
|
||||||
|
|
||||||
bool VoteMenuHandler::InitializeVoting(IBaseMenu *menu,
|
bool VoteMenuHandler::InitializeVoting(IBaseMenu *menu,
|
||||||
IMenuHandler *handler,
|
IMenuHandler *handler,
|
||||||
unsigned int time,
|
unsigned int time,
|
||||||
@ -187,7 +261,9 @@ bool VoteMenuHandler::InitializeVoting(IBaseMenu *menu,
|
|||||||
m_Votes[i] = 0;
|
m_Votes[i] = 0;
|
||||||
}
|
}
|
||||||
m_Votes.resize(m_Items, 0);
|
m_Votes.resize(m_Items, 0);
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
for (unsigned int i=0; i<m_Items; i++)
|
for (unsigned int i=0; i<m_Items; i++)
|
||||||
{
|
{
|
||||||
m_Votes[i] = 0;
|
m_Votes[i] = 0;
|
||||||
@ -252,7 +328,9 @@ void VoteMenuHandler::EndVoting()
|
|||||||
if (fVoteDelay < 1.0)
|
if (fVoteDelay < 1.0)
|
||||||
{
|
{
|
||||||
g_next_vote = 0.0;
|
g_next_vote = 0.0;
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
g_next_vote = gpGlobals->curtime + fVoteDelay;
|
g_next_vote = gpGlobals->curtime + fVoteDelay;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -72,6 +72,9 @@ public:
|
|||||||
IBaseMenu *GetCurrentMenu();
|
IBaseMenu *GetCurrentMenu();
|
||||||
bool IsCancelling();
|
bool IsCancelling();
|
||||||
unsigned int GetRemainingVoteDelay();
|
unsigned int GetRemainingVoteDelay();
|
||||||
|
bool IsClientInVotePool(int client);
|
||||||
|
bool GetClientVoteChoice(int client, unsigned int *pItem);
|
||||||
|
bool RedrawToClient(int client);
|
||||||
private:
|
private:
|
||||||
void Reset(IMenuHandler *mh);
|
void Reset(IMenuHandler *mh);
|
||||||
void DecrementPlayerCount();
|
void DecrementPlayerCount();
|
||||||
@ -93,6 +96,8 @@ private:
|
|||||||
unsigned int m_NumVotes;
|
unsigned int m_NumVotes;
|
||||||
unsigned int m_VoteTime;
|
unsigned int m_VoteTime;
|
||||||
unsigned int m_VoteFlags;
|
unsigned int m_VoteFlags;
|
||||||
|
float m_fStartTime;
|
||||||
|
unsigned int m_nMenuTime;
|
||||||
int m_ClientVotes[256+1];
|
int m_ClientVotes[256+1];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1405,6 +1405,49 @@ static cell_t GetMenuSelectionPosition(IPluginContext *pContext, const cell_t *p
|
|||||||
return *s_CurSelectPosition;
|
return *s_CurSelectPosition;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static cell_t IsClientInVotePool(IPluginContext *pContext, const cell_t *params)
|
||||||
|
{
|
||||||
|
int client;
|
||||||
|
IGamePlayer *pPlayer;
|
||||||
|
|
||||||
|
client = params[1];
|
||||||
|
if ((pPlayer = g_Players.GetPlayerByIndex(client)) == NULL)
|
||||||
|
{
|
||||||
|
return pContext->ThrowNativeError("Invalid client index %d", client);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!g_Menus.IsVoteInProgress())
|
||||||
|
{
|
||||||
|
return pContext->ThrowNativeError("No vote is in progress");
|
||||||
|
}
|
||||||
|
|
||||||
|
return g_Menus.IsClientInVotePool(client) ? 1 : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static cell_t RedrawClientVoteMenu(IPluginContext *pContext, const cell_t *params)
|
||||||
|
{
|
||||||
|
int client;
|
||||||
|
IGamePlayer *pPlayer;
|
||||||
|
|
||||||
|
client = params[1];
|
||||||
|
if ((pPlayer = g_Players.GetPlayerByIndex(client)) == NULL)
|
||||||
|
{
|
||||||
|
return pContext->ThrowNativeError("Invalid client index %d", client);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!g_Menus.IsVoteInProgress())
|
||||||
|
{
|
||||||
|
return pContext->ThrowNativeError("No vote is in progress");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!g_Menus.IsClientInVotePool(client))
|
||||||
|
{
|
||||||
|
return pContext->ThrowNativeError("Client is not in the voting pool");
|
||||||
|
}
|
||||||
|
|
||||||
|
return g_Menus.RedrawClientVoteMenu(client) ? 1 : 0;
|
||||||
|
}
|
||||||
|
|
||||||
class EmptyMenuHandler : public IMenuHandler
|
class EmptyMenuHandler : public IMenuHandler
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -1505,7 +1548,9 @@ REGISTER_NATIVES(menuNatives)
|
|||||||
{"GetPanelStyle", GetPanelStyle},
|
{"GetPanelStyle", GetPanelStyle},
|
||||||
{"InsertMenuItem", InsertMenuItem},
|
{"InsertMenuItem", InsertMenuItem},
|
||||||
{"InternalShowMenu", InternalShowMenu},
|
{"InternalShowMenu", InternalShowMenu},
|
||||||
|
{"IsClientInVotePool", IsClientInVotePool},
|
||||||
{"IsVoteInProgress", IsVoteInProgress},
|
{"IsVoteInProgress", IsVoteInProgress},
|
||||||
|
{"RedrawClientVoteMenu", RedrawClientVoteMenu},
|
||||||
{"RedrawMenuItem", RedrawMenuItem},
|
{"RedrawMenuItem", RedrawMenuItem},
|
||||||
{"RemoveAllMenuItems", RemoveAllMenuItems},
|
{"RemoveAllMenuItems", RemoveAllMenuItems},
|
||||||
{"RemoveMenuItem", RemoveMenuItem},
|
{"RemoveMenuItem", RemoveMenuItem},
|
||||||
|
@ -540,6 +540,28 @@ native SetVoteResultCallback(Handle:menu, VoteHandler:callback);
|
|||||||
*/
|
*/
|
||||||
native CheckVoteDelay();
|
native CheckVoteDelay();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns whether a client is in the pool of clients allowed
|
||||||
|
* to participate in the current vote. This is determined by
|
||||||
|
* the client list passed to StartVote().
|
||||||
|
*
|
||||||
|
* @param client Client index.
|
||||||
|
* @return True if client is allowed to vote, false otherwise.
|
||||||
|
* @error If no vote is in progress or client index is invalid.
|
||||||
|
*/
|
||||||
|
native bool:IsClientInVotePool(client);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Redraws the current vote menu to a client in the voting pool.
|
||||||
|
*
|
||||||
|
* @param client Client index.
|
||||||
|
* @return True on success, false if the client is in the vote pool
|
||||||
|
* but cannot vote again.
|
||||||
|
* @error No vote in progress, client is not in the voting pool,
|
||||||
|
* or client index is invalid.
|
||||||
|
*/
|
||||||
|
native bool:RedrawClientVoteMenu(client);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a style's global Handle.
|
* Returns a style's global Handle.
|
||||||
*
|
*
|
||||||
|
@ -36,7 +36,7 @@
|
|||||||
#include <IHandleSys.h>
|
#include <IHandleSys.h>
|
||||||
|
|
||||||
#define SMINTERFACE_MENUMANAGER_NAME "IMenuManager"
|
#define SMINTERFACE_MENUMANAGER_NAME "IMenuManager"
|
||||||
#define SMINTERFACE_MENUMANAGER_VERSION 14
|
#define SMINTERFACE_MENUMANAGER_VERSION 15
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @file IMenuManager.h
|
* @file IMenuManager.h
|
||||||
@ -897,6 +897,23 @@ namespace SourceMod
|
|||||||
* @return Number of seconds to wait.
|
* @return Number of seconds to wait.
|
||||||
*/
|
*/
|
||||||
virtual unsigned int GetRemainingVoteDelay() =0;
|
virtual unsigned int GetRemainingVoteDelay() =0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Returns whether a client is in the "allowed to vote" pool determined
|
||||||
|
* by the initial call to StartVote().
|
||||||
|
*
|
||||||
|
* @param client Client index.
|
||||||
|
* @return True if client is allowed to vote, false on failure.
|
||||||
|
*/
|
||||||
|
virtual bool IsClientInVotePool(int client) =0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Redraws the current vote menu to a client in the voting pool.
|
||||||
|
*
|
||||||
|
* @param client Client index.
|
||||||
|
* @return True on success, false if client is not allowed to vote.
|
||||||
|
*/
|
||||||
|
virtual bool RedrawClientVoteMenu(int client) =0;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -222,32 +222,14 @@
|
|||||||
"en" "The given player is not fully in-game yet."
|
"en" "The given player is not fully in-game yet."
|
||||||
}
|
}
|
||||||
|
|
||||||
/* :UNUSED: */
|
"Cannot participate in vote"
|
||||||
"Played Sound"
|
|
||||||
{
|
{
|
||||||
"#format" "{1:s}"
|
"en" "You cannot participate in this vote."
|
||||||
"en" "Played sound on player '{1}'"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* :UNUSED: */
|
"Cannot change vote"
|
||||||
"Slapped player"
|
|
||||||
{
|
{
|
||||||
"#format" "{1:s}"
|
"en" "You cannot change your selection for this vote."
|
||||||
"en" "Slapped player '{1}'"
|
|
||||||
}
|
|
||||||
|
|
||||||
/* :UNUSED: */
|
|
||||||
"Slayed player"
|
|
||||||
{
|
|
||||||
"#format" "{1:s}"
|
|
||||||
"en" "Slayed player '{1}'"
|
|
||||||
}
|
|
||||||
|
|
||||||
/* :UNUSED: */
|
|
||||||
"Kicked player"
|
|
||||||
{
|
|
||||||
"#format" "{1:s}"
|
|
||||||
"en" "Kicked player '{1}'"
|
|
||||||
}
|
}
|
||||||
"On"
|
"On"
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user