if(to.ready == 0)
nags |= 2;
}
- if(votecalled)
+ if(vote_called)
{
nags |= 4;
if(to.vote_selection == 0)
}
if(nags & 128)
- WriteString(MSG_ENTITY, votecalledvote_display);
+ WriteString(MSG_ENTITY, vote_called_display);
if(nags & 1)
{
FOR_EACH_CLIENT(tmp_player) { tmp_player.vote_selection = 0; }
- if(votecalled)
+ if(vote_called)
{
- strunzone(votecalledvote);
- strunzone(votecalledvote_display);
+ strunzone(vote_called_command);
+ strunzone(vote_called_display);
}
- votecalled = FALSE;
- votecalledmaster = FALSE;
- votefinished = 0;
- votecalledvote = string_null;
- votecalledvote_display = string_null;
+ vote_called = VOTE_NULL;
+ vote_endtime = 0;
+ vote_called_command = string_null;
+ vote_called_display = string_null;
vote_parsed_command = string_null;
vote_parsed_display = string_null;
void VoteStop(entity stopper)
{
- bprint("\{1}^2* ^3", VoteCommand_getname(stopper), "^2 stopped ^3", VoteCommand_getname(votecaller), "^2's vote\n");
+ bprint("\{1}^2* ^3", GetCallerName(stopper), "^2 stopped ^3", GetCallerName(vote_caller), "^2's vote\n");
if(autocvar_sv_eventlog) { GameLogEcho(strcat(":vote:vstop:", ftos(stopper.playerid))); }
// Don't force them to wait for next vote, this way they can e.g. correct their vote.
- if((votecaller) && (stopper == votecaller)) { votecaller.vote_next = time + autocvar_sv_vote_stop; }
+ if((vote_caller) && (stopper == vote_caller)) { vote_caller.vote_waittime = time + autocvar_sv_vote_stop; }
VoteReset();
}
-void VoteThink()
-{
- if(votefinished > 0) // a vote was called
- if(time > votefinished) // time is up
- {
- VoteCount();
- }
-
- return;
-}
-
void VoteAccept()
{
- bprint("\{1}^2* ^3", VoteCommand_getname(votecaller), "^2's vote for ^1", votecalledvote_display, "^2 was accepted\n");
+ bprint("\{1}^2* ^3", GetCallerName(vote_caller), "^2's vote for ^1", vote_called_display, "^2 was accepted\n");
- if(votecalledmaster && votecaller)
- votecaller.vote_master = 1;
+ if((vote_called == VOTE_MASTER) && vote_caller)
+ vote_caller.vote_master = 1;
else
- localcmd(strcat(votecalledvote, "\n"));
+ localcmd(strcat(vote_called_command, "\n"));
- if(votecaller) { votecaller.vote_next = 0; } // people like your votes, you don't need to wait to vote again // todo separate anti-spam even for succeeded votes
+ if(vote_caller) { vote_caller.vote_waittime = 0; } // people like your votes, you don't need to wait to vote again // todo separate anti-spam even for succeeded votes
VoteReset();
Announce("voteaccept");
void VoteReject()
{
- bprint("\{1}^2* ^3", VoteCommand_getname(votecaller), "^2's vote for ", votecalledvote_display, "^2 was rejected\n");
+ bprint("\{1}^2* ^3", GetCallerName(vote_caller), "^2's vote for ", vote_called_display, "^2 was rejected\n");
VoteReset();
Announce("votefail");
}
void VoteTimeout()
{
- bprint("\{1}^2* ^3", VoteCommand_getname(votecaller), "^2's vote for ", votecalledvote_display, "^2 timed out\n");
+ bprint("\{1}^2* ^3", GetCallerName(vote_caller), "^2's vote for ", vote_called_display, "^2 timed out\n");
VoteReset();
Announce("votefail");
}
}
// Check to see if there are enough players on the server to allow master voting... otherwise, vote master could be used for evil.
- if(votecalledmaster && autocvar_sv_vote_master_playerlimit > vote_player_count)
+ if((vote_called == VOTE_MASTER) && autocvar_sv_vote_master_playerlimit > vote_player_count)
{
- if(votecaller) { votecaller.vote_next = 0; }
- print_to(votecaller, "^1There are not enough players on this server to allow you to become vote master.");
+ if(vote_caller) { vote_caller.vote_waittime = 0; }
+ print_to(vote_caller, "^1There are not enough players on this server to allow you to become vote master.");
VoteReset();
return;
}
}
// there is not enough votes in either direction, now lets just calculate what the voters have said
- if(time > votefinished)
+ if(time > vote_endtime)
{
final_needed_votes = vote_needed_overall;
}
}
+void VoteThink()
+{
+ if(vote_endtime > 0) // a vote was called
+ if(time > vote_endtime) // time is up
+ {
+ VoteCount();
+ }
+
+ return;
+}
+
// =======================
// Game logic for warmup
return FALSE;
}
-string VoteCommand_getprefix(entity caller)
-{
- if(caller)
- return "cmd";
- else
- return "sv_cmd";
-}
-
-string VoteCommand_getname(entity caller)
-{
- if(caller)
- return caller.netname;
- else
- return ((autocvar_sv_adminnick != "") ? autocvar_sv_adminnick : autocvar_hostname);
-}
-
string VoteCommand_extractcommand(string input, float startpos, float argc)
{
string output;
{
case CMD_REQUEST_COMMAND:
{
- if not(votecalled) { print_to(caller, "^1No vote called."); }
+ if not(vote_called) { print_to(caller, "^1No vote called."); }
else if not(caller.vote_selection == VOTE_SELECT_NULL || autocvar_sv_vote_change) { print_to(caller, "^1You have already voted."); }
else // everything went okay, continue changing vote
vote_command = VoteCommand_extractcommand(vote_command, 2, argc);
if not(autocvar_sv_vote_call || !caller) { print_to(caller, "^1Vote calling is not allowed."); }
- else if(votecalled) { print_to(caller, "^1There is already a vote called."); }
+ else if(vote_called) { print_to(caller, "^1There is already a vote called."); }
else if(!spectators_allowed && (caller && (caller.classname != "player"))) { print_to(caller, "^1Only players can call a vote."); }
else if(timeoutStatus) { print_to(caller, "^1You can not call a vote while a timeout is active."); }
- else if(caller && (time < caller.vote_next)) { print_to(caller, strcat("^1You have to wait ^2", ftos(ceil(caller.vote_next - time)), "^1 seconds before you can again call a vote.")); }
+ else if(caller && (time < caller.vote_waittime)) { print_to(caller, strcat("^1You have to wait ^2", ftos(ceil(caller.vote_waittime - time)), "^1 seconds before you can again call a vote.")); }
else if not(VoteCommand_checknasty(vote_command)) { print_to(caller, "^1Syntax error in command, see 'vhelp' for more info."); }
else if not(VoteCommand_parse(caller, vote_command, autocvar_sv_vote_commands, 2, argc)) { print_to(caller, "^1This command is not acceptable, see 'vhelp' for more info."); }
else // everything went okay, continue with calling the vote // TODO: fixes to make this more compatible with sv_cmd
{
- votecalled = TRUE;
- votecalledmaster = FALSE;
- votecalledvote = strzone(vote_parsed_command);
- votecalledvote_display = strzone(vote_parsed_display);
- votefinished = time + autocvar_sv_vote_timeout;
- votecaller = caller; // remember who called the vote
+ vote_called = VOTE_NORMAL;
+ vote_called_command = strzone(vote_parsed_command);
+ vote_called_display = strzone(vote_parsed_display);
+ vote_endtime = time + autocvar_sv_vote_timeout;
+ vote_caller = caller; // remember who called the vote
if(caller)
{
caller.vote_selection = VOTE_SELECT_ACCEPT;
- caller.vote_next = time + autocvar_sv_vote_wait;
+ caller.vote_waittime = time + autocvar_sv_vote_wait;
msg_entity = caller; // todo: what is this for?
}
FOR_EACH_REALCLIENT(tmp_player) { ++tmp_playercount; }
if(tmp_playercount > 1) { Announce("votecall"); } // don't announce a "vote now" sound if player is alone
- bprint("\{1}^2* ^3", VoteCommand_getname(votecaller), "^2 calls a vote for ", votecalledvote_display, "\n");
- if(autocvar_sv_eventlog) { GameLogEcho(strcat(":vote:vcall:", ftos(votecaller.playerid), ":", votecalledvote_display)); }
+ bprint("\{1}^2* ^3", GetCallerName(vote_caller), "^2 calls a vote for ", vote_called_display, "\n");
+ if(autocvar_sv_eventlog) { GameLogEcho(strcat(":vote:vcall:", ftos(vote_caller.playerid), ":", vote_called_display)); }
Nagger_VoteChanged();
VoteCount(); // needed if you are the only one
}
{
localcmd(strcat(vote_parsed_command, "\n"));
print_to(caller, strcat("Executing command '", vote_parsed_display, "' on server."));
- bprint("\{1}^2* ^3", VoteCommand_getname(caller), "^2 used their ^3master^2 status to do \"^2", vote_parsed_display, "^2\".\n");
+ bprint("\{1}^2* ^3", GetCallerName(caller), "^2 used their ^3master^2 status to do \"^2", vote_parsed_display, "^2\".\n");
if(autocvar_sv_eventlog) { GameLogEcho(strcat(":vote:vdo:", ftos(caller.playerid), ":", vote_parsed_display)); }
}
{
if not(autocvar_sv_vote_master_password != "") { print_to(caller, "^1Login to vote master is not allowed."); }
else if(caller.vote_master) { print_to(caller, "^1You are already logged in as vote master."); }
- else if not(autocvar_sv_vote_master_password == argv(3)) { print_to(caller, strcat("Rejected vote master login from ", VoteCommand_getname(caller))); }
+ else if not(autocvar_sv_vote_master_password == argv(3)) { print_to(caller, strcat("Rejected vote master login from ", GetCallerName(caller))); }
else // everything went okay, proceed with giving this player master privilages
{
caller.vote_master = TRUE;
- print_to(caller, strcat("Accepted vote master login from ", VoteCommand_getname(caller)));
- bprint("\{1}^2* ^3", VoteCommand_getname(caller), "^2 logged in as ^3master^2\n");
+ print_to(caller, strcat("Accepted vote master login from ", GetCallerName(caller)));
+ bprint("\{1}^2* ^3", GetCallerName(caller), "^2 logged in as ^3master^2\n");
if(autocvar_sv_eventlog) { GameLogEcho(strcat(":vote:vlogin:", ftos(caller.playerid))); }
}
default: // calling a vote for master
{
if not(autocvar_sv_vote_master_callable) { print_to(caller, "^1Vote to become vote master is not allowed."); }
- else if(votecalled) { print_to(caller, "^1There is already a vote called."); }
+ else if(vote_called) { print_to(caller, "^1There is already a vote called."); }
else // everything went okay, continue with creating vote
{
- votecalled = TRUE;
- votecalledmaster = TRUE;
- votecalledvote = strzone("XXX");
- votecalledvote_display = strzone("^3master");
- votefinished = time + autocvar_sv_vote_timeout;
- votecaller = caller;
+ vote_called = VOTE_MASTER;
+ vote_called_command = strzone("XXX");
+ vote_called_display = strzone("^3master");
+ vote_endtime = time + autocvar_sv_vote_timeout;
+ vote_caller = caller;
caller.vote_selection = VOTE_SELECT_ACCEPT;
- caller.vote_next = time + autocvar_sv_vote_wait;
+ caller.vote_waittime = time + autocvar_sv_vote_wait;
- bprint("\{1}^2* ^3", VoteCommand_getname(votecaller), "^2 calls a vote to become ^3master^2.\n");
- if(autocvar_sv_eventlog) { GameLogEcho(strcat(":vote:vcall:", ftos(votecaller.playerid), ":", votecalledvote_display)); }
+ bprint("\{1}^2* ^3", GetCallerName(vote_caller), "^2 calls a vote to become ^3master^2.\n");
+ if(autocvar_sv_eventlog) { GameLogEcho(strcat(":vote:vcall:", ftos(vote_caller.playerid), ":", vote_called_display)); }
Nagger_VoteChanged();
VoteCount(); // needed if you are the only one
}
{
case CMD_REQUEST_COMMAND:
{
- if not(votecalled) { print_to(caller, "^1No vote called."); }
+ if not(vote_called) { print_to(caller, "^1No vote called."); }
else if not(caller.vote_selection == VOTE_SELECT_NULL || autocvar_sv_vote_change) { print_to(caller, "^1You have already voted."); }
else // everything went okay, continue changing vote
{
case CMD_REQUEST_COMMAND:
{
- if(votecalled)
- print_to(caller, strcat("^7Vote for ", votecalledvote_display, "^7 called by ^7", VoteCommand_getname(votecaller), "^7."));
+ if(vote_called)
+ print_to(caller, strcat("^7Vote for ", vote_called_display, "^7 called by ^7", GetCallerName(vote_caller), "^7."));
else
print_to(caller, "^1No vote called.");
{
case CMD_REQUEST_COMMAND:
{
- if not(votecalled) { print_to(caller, "^1No vote called."); }
- else if((caller == votecaller) || !caller || caller.vote_master) { VoteStop(caller); }
+ if not(vote_called) { print_to(caller, "^1No vote called."); }
+ else if((caller == vote_caller) || !caller || caller.vote_master) { VoteStop(caller); }
else { print_to(caller, "^1You are not allowed to stop that vote."); }
return;
{
case CMD_REQUEST_COMMAND:
{
- if not(votecalled) { print_to(caller, "^1No vote called."); }
+ if not(vote_called) { print_to(caller, "^1No vote called."); }
if not(caller.vote_selection == VOTE_SELECT_NULL || autocvar_sv_vote_change) { print_to(caller, "^1You have already voted."); }
else // everything went okay, continue changing vote
void VoteCommand_macro_help(entity caller, float argc)
{
- string command_origin = VoteCommand_getprefix(caller);
+ string command_origin = GetCommandPrefix(caller);
if(argc == 2) // help display listing all commands
{
}
default:
- print_to(caller, strcat("Unknown vote command", ((argv(1) != "") ? strcat(" \"", argv(1), "\"") : ""), ". For a list of supported commands, try ", VoteCommand_getprefix(caller), " help.\n"));
+ print_to(caller, strcat("Unknown vote command", ((argv(1) != "") ? strcat(" \"", argv(1), "\"") : ""), ". For a list of supported commands, try ", GetCommandPrefix(caller), " help.\n"));
case CMD_REQUEST_USAGE:
{
VoteCommand_macro_help(caller, argc);
+// ================================================
+// Declarations for the vote system/vote commands
+// Last updated: December 14th, 2011
+// ================================================
+
+// definitions for command selection between progs
#define VC_ASGNMNT_BOTH 1
#define VC_ASGNMNT_CLIENTONLY 2
#define VC_ASGNMNT_SERVERONLY 3
+// vote selection definitions
#define VOTE_SELECT_ABSTAIN -2
#define VOTE_SELECT_REJECT -1
#define VOTE_SELECT_NULL 0
#define VOTE_SELECT_ACCEPT 1
-string vote_parsed_command;
-string vote_parsed_display;
+// different statuses of the current vote
+#define VOTE_NULL 0
+#define VOTE_NORMAL 1
+#define VOTE_MASTER 2
-float votecalled;
-string votecalledvote;
-string votecalledvote_display;
-float votecalledmaster;
-entity votecaller;
-float votefinished;
-.float vote_master;
-.float vote_next;
-.float vote_selection;
-float vote_accept_count;
-float vote_reject_count;
-float vote_abstain_count;
-float vote_needed_overall;
+// global vote information declarations
+entity vote_caller; // original caller of the current vote
+float vote_called; // stores status of current vote (See VOTE_*)
+float vote_endtime; // time when the vote is finished
+float vote_accept_count; // total amount of players who accept the vote (counted by VoteCount() function)
+float vote_reject_count; // same as above, but rejected
+float vote_abstain_count; // same as above, but abstained
+float vote_needed_overall; // total amount of players NEEDED for a vote to pass (based on sv_vote_majority_factor)
+.float vote_master; // flag for if the player has vote master privelages
+.float vote_waittime; // flag for how long the player must wait before they can vote again
+.float vote_selection; // flag for which vote selection the player has made (See VOTE_SELECT_*)
+string vote_called_command; // command sent by client
+string vote_called_display; // visual string of command sent by client
+string vote_parsed_command; // command which is fixed after being parsed
+string vote_parsed_display; // visual string which is fixed after being parsed
-string VoteCommand_getname(entity caller);
-void VoteCommand(float request, entity caller, float argc, string vote_command);
-void VoteHelp(entity e);
+// allow functions to be used in other code like g_world.qc and teamplay.qc
void VoteThink();
void VoteReset();
-void VoteAccept();
-void VoteReject();
-void VoteTimeout();
-void VoteStop(entity stopper);
-void VoteSpam(float notvoters, float mincount, string result);
-void VoteCount();
-
-// =========================
-// warmup and nagger stuff
-// =========================
+// warmup and nagger stuff
#define RESTART_COUNTDOWN 10
entity nagger;
-.float ready;
-float readycount;
-float readyrestart_happened;
+float readycount; // amount of players who are ready
+float readyrestart_happened; // keeps track of whether a restart has already happened
float restart_mapalreadyrestarted; // bool, indicates whether reset_map() was already executed
+.float ready; // flag for if a player is ready
void ReadyCount();
\ No newline at end of file