]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Almost done re-writting timeout/timein stuff
authorSamual <samual@xonotic.org>
Tue, 27 Dec 2011 17:20:06 +0000 (12:20 -0500)
committerSamual <samual@xonotic.org>
Tue, 27 Dec 2011 17:20:06 +0000 (12:20 -0500)
qcsrc/server/command/common.qc
qcsrc/server/command/common.qh
qcsrc/server/command/vote.qc
qcsrc/server/defs.qh

index 58ad46be6339befb77b2414f451a683c23c9fc8b..2e40340206ec6bb120cc9b92553b269bce81be1f 100644 (file)
@@ -1,6 +1,6 @@
 // ====================================================
 //  Shared code for server commands, written by Samual
-//  Last updated: December 25th, 2011
+//  Last updated: December 27th, 2011
 // ====================================================
 
 // select the proper prefix for usage and other messages
@@ -100,6 +100,11 @@ void print_to(entity to, string input)
         print(input, "\n");
 }
 
+// ==========================================
+//  Supporting functions for common commands
+// ==========================================
+
+
 
 // ===================================================
 //  Common commands used in both sv_cmd.qc and cmd.qc
@@ -367,38 +372,39 @@ void CommonCommand_time(float request, entity caller)
        }
 }
 
-void CommonCommand_timein(float request, entity caller) // todo entirely re-write this
+void CommonCommand_timein(float request, entity caller)
 {
        switch(request)
        {
                case CMD_REQUEST_COMMAND:
                {
-                       if(caller.flags & FL_CLIENT)
+                       if(autocvar_sv_timeout)
                        {
-                               if(autocvar_sv_timeout)
+                               if not(timeout_status) { print_to(caller, "^7Error: There is no active timeout called."); }
+                               else if(caller && (caller != timeout_caller)) { print_to(caller, "^7Error: You are not allowed to stop the active timeout."); }
+                                       
+                               else // everything should be okay, continue aborting timeout
                                {
-                                       if (!timeoutStatus)
-                                               return print_to(caller, "^7Error: There is no active timeout which could be aborted!");
-                                       if (caller != timeoutInitiator)
-                                               return print_to(caller, "^7Error: You may not abort the active timeout. Only the player who called it can do that!");
-                                               
-                                       if (timeoutStatus == 1) 
-                                       {
-                                               remainingTimeoutTime = timeoutStatus = 0;
-                                               timeoutHandler.nextthink = time; //timeoutHandler has to take care of it immediately
-                                               bprint(strcat("^7The timeout was aborted by ", caller.netname, " !\n"));
-                                       }
-                                       else if (timeoutStatus == 2) 
+                                       switch(timeout_status)
                                        {
-                                               //only shorten the remainingTimeoutTime if it makes sense
-                                               if( remainingTimeoutTime > (autocvar_sv_timeout_resumetime + 1) ) 
+                                               case TIMEOUT_LEADTIME:
                                                {
+                                                       timeout_status = TIMEOUT_INACTIVE;
+                                                       timeout_time = 0;
+                                                       timeout_handler.nextthink = time; // timeout_handler has to take care of it immediately
+                                                       bprint(strcat("^7The timeout was aborted by ", caller.netname, " !\n"));
+                                                       return;
+                                               }
+                                               
+                                               case TIMEOUT_ACTIVE:
+                                               {
+                                                       timeout_time = autocvar_sv_timeout_resumetime;
+                                                       timeoutHandler.nextthink = time; // timeout_handler has to take care of it immediately
                                                        bprint(strcat("^1Attention: ^7", caller.netname, " resumed the game! Prepare for battle!\n"));
-                                                       remainingTimeoutTime = autocvar_sv_timeout_resumetime;
-                                                       timeoutHandler.nextthink = time; //timeoutHandler has to take care of it immediately
+                                                       return;
                                                }
-                                               else
-                                                       print_to(caller, "^7Error: Your resumegame call was discarded!");
+                                               
+                                               default: dprint("timeout status was inactive, but this code was executed anyway?"); return;
                                        }
                                }
                        }
@@ -423,47 +429,30 @@ void CommonCommand_timeout(float request, entity caller) // DEAR GOD THIS COMMAN
                {
                        if(autocvar_sv_timeout) 
                        {
-                               if(vote_called) { print_to(caller, "^7Error: You can not call a timeout while a vote is active."); }
+                               float last_possible_timeout = ((autocvar_timelimit * 60) - autocvar_sv_timeout_leadtime - 1);
+                               
+                               if(timeout_status) { print_to(caller, "^7Error: A timeout is already active."); }
+                               else if(vote_called) { print_to(caller, "^7Error: You can not call a timeout while a vote is active."); }
                                else if(inWarmupStage && !g_warmup_allow_timeout) { print_to(caller, "^7Error: You can not call a timeout in warmup-stage."); }
                                else if(time < game_starttime) { print_to(caller, "^7Error: You can not call a timeout while the map is being restarted."); }
-                               else if(caller && (caller.allowedTimeouts < 1)) { print_to(caller, "^7Error: You already used all your timeout calls for this map."); }
+                               else if(caller && (caller.allowed_timeouts < 1)) { print_to(caller, "^7Error: You already used all your timeout calls for this map."); }
                                else if(caller && (caller.classname != "player")) { print_to(caller, "^7Error: You must be a player to call a timeout."); }
+                               else if((autocvar_timelimit) && (last_possible_timeout < time - game_starttime)) { print_to(caller, "^7Error: It is too late to call a timeout now!"); }
                                
                                else // everything should be okay, proceed with starting the timeout
-                               {
-                                       if (timeoutStatus != 2) {
-                                               //if the map uses a timelimit make sure that timeout cannot be called right before the map ends
-                                               if (autocvar_timelimit) {
-                                                       //a timelimit was used
-                                                       float myTl;
-                                                       myTl = autocvar_timelimit;
-
-                                                       float lastPossibleTimeout;
-                                                       lastPossibleTimeout = (myTl*60) - autocvar_sv_timeout_leadtime - 1;
-
-                                                       if (lastPossibleTimeout < time - game_starttime)
-                                                               return print_to(caller, "^7Error: It is too late to call a timeout now!");
-                                               }
-                                       }
-                                               
-                                       if(caller) { caller.allowedTimeouts -= 1; }
+                               {                                       
+                                       if(caller) { caller.allowed_timeouts -= 1; }
                                        
                                        bprint(GetCallerName(caller), " ^7called a timeout", (caller ? strcat(" (", ftos(caller.allowedTimeouts), " timeouts left)") : string_null), "!\n"); // write a bprint who started the timeout (and how many they have left)
                                        
-                                       remainingTimeoutTime = autocvar_sv_timeout_length;
-                                       remainingLeadTime = autocvar_sv_timeout_leadtime;
-                                       
-                                       timeoutInitiator = caller;
-                                       
-                                       // if another timeout was already active, don't change its status (which was 1 or 2) to 1
-                                       if (timeoutStatus == 0) 
-                                       {
-                                               timeoutStatus = 1;
-                                               timeoutHandler = spawn();
-                                               timeoutHandler.think = timeoutHandler_Think;
-                                       }
+                                       timeout_status = TIMEOUT_LEADTIME;
+                                       timeout_caller = caller;
+                                       timeout_time = autocvar_sv_timeout_length;
+                                       timeout_leadtime = autocvar_sv_timeout_leadtime;
                                        
-                                       timeoutHandler.nextthink = time; //always let the entity think asap
+                                       timeout_handler = spawn();
+                                       timeout_handler.think = timeout_handler_think;
+                                       timeout_handler.nextthink = time; // always let the entity think asap
 
                                        Announce("timeoutcalled");
                                }
index 010d56b060f0b763073a21625c4636afd12ff1d7..f11a25338fdeded16d56f2fab95ad3774a8cf4c1 100644 (file)
@@ -1,9 +1,32 @@
 // ============================================================
 //  Shared declarations for server commands, written by Samual
-//  Last updated: December 13th, 2011
+//  Last updated: December 27th, 2011
 // ============================================================
 
+// client verification results
 #define CLIENT_ACCEPTABLE 1
 #define CLIENT_DOESNT_EXIST -1
 #define CLIENT_NOT_REAL -2
-#define CLIENT_NOT_BOT -3
\ No newline at end of file
+#define CLIENT_NOT_BOT -3
+
+// definitions for timeouts
+#define TIMEOUT_INACTIVE 0
+#define TIMEOUT_LEADTIME 1
+#define TIMEOUT_ACTIVE 2
+
+// timeout which pauses the game by setting the slowmo value extremely low.
+#define TIMEOUT_SLOWMO_VALUE 0.0001
+
+// global timeout information declarations
+entity timeout_caller; // contains the entity of the player who started the last timeout
+entity timeout_handler; // responsible for centerprinting the timeout countdowns and playing sounds
+float sys_frametime; // gets initialised in worldspawn, saves the value from autocvar_sys_ticrate
+float orig_slowmo; // contains the value of autocvar_slowmo so that, after timeout finished, it isn't set to slowmo 1 necessarily
+float timeout_time; // contains the time in seconds that the active timeout has left
+float timeout_leadtime; // contains the number of seconds left of the leadtime (before the timeout starts)
+float timeout_status; // (values: 0, 1, 2) contains whether a timeout is not active (0), was called but still at leadtime (1) or is active (2)
+.float allowed_timeouts; // contains the number of allowed timeouts for each player
+.vector lastV_angle; //used when pausing the game in order to force the player to keep his old view angle fixed
+
+// allow functions to be used in other code like g_world.qc and teamplay.qc
+void timeout_handler_think();
\ No newline at end of file
index 69aa2f68684d652f2884a4c1fcc4b390fddf80a6..1c7b170220bc8123919fb05fd3af5c3f531abf15 100644 (file)
@@ -1,6 +1,6 @@
 // =============================================
 //  Server side voting code, reworked by Samual
-//  Last updated: December 14th, 2011
+//  Last updated: December 27th, 2011
 // =============================================
 
 //  Nagger for players to know status of voting
index 178ccf0b9f206cc445dbc929232652db58b8a155..90005edb33793ba0a885c200ab59a2e12ad111e9 100644 (file)
@@ -284,19 +284,6 @@ void checkSpectatorBlock();
 float nJoinAllowed(float includeMe);
 #define PREVENT_JOIN_TEXT "^1You may not join the game at this time.\n\nThe player limit reached maximum capacity."
 
-//sv_timeout: pauses the game by setting the gamespeed to a really low value (see TIMEOUT_SLOWMO_VALUE)
-#define TIMEOUT_SLOWMO_VALUE 0.0001
-float sys_frametime; // gets initialised in worlspawn, saves the value from autocvar_sys_ticrate
-float remainingTimeoutTime; // contains the time in seconds that the active timeout has left
-float remainingLeadTime; // contains the number of seconds left of the leadtime (before the timeout starts)
-float timeoutStatus; // (values: 0, 1, 2) contains whether a timeout is not active (0), was called but still at leadtime (1) or is active (2)
-.float allowedTimeouts; // contains the number of allowed timeouts for each player
-entity timeoutInitiator; // contains the entity of the player who started the last timeout
-float orig_slowmo; // contains the value of autocvar_slowmo so that, after timeout finished, it isn't set to slowmo 1 necessarily
-.vector lastV_angle; //used when pausing the game in order to force the player to keep his old view angle fixed
-entity timeoutHandler; //responsible for centerprinting the timeout countdowns and playing sounds
-void timeoutHandler_Think();
-
 .float spawnshieldtime;
 
 .float lms_nextcheck;